package com.youlu.campus.web.leads.controller;

import com.youlu.campus.web.common.base.RequestContext;
import com.youlu.campus.web.leads.dto.SalesLeadsCreateRequest;
import com.youlu.campus.web.leads.dto.TeacherInfoQueryRequest;
import com.youlu.campus.web.leads.entity.SalesLeads;
import com.youlu.campus.web.leads.entity.TeacherInfo;
import com.youlu.campus.web.leads.service.SalesLeadsService;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * 成长API
 */
@RestController
public class SalesLeadsController {

    @Autowired
    private SalesLeadsService salesLeadsService;

    /**
     * 新建成长
     * 备注：新增
     * 参数：request - 成长创建请求类
     * 返回：200-请求成功，返回Boolean类型结果
     */
    @PostMapping("/mini-app/sales-leads/create")
    public QResult createSalesLeads(@RequestBody @Valid SalesLeadsCreateRequest request) {
        SalesLeads salesLeads = new SalesLeads();
        BeanUtils.copyProperties(request, salesLeads);
        salesLeads.setUserId(RequestContext.getUserId());
        return QResult.success(salesLeadsService.create(salesLeads));
    }

    /**
     * 获取老师信息
     * 备注：老师信息
     * 参数：request - 老师信息请求类
     * 返回：200-请求成功，返回TeacherInfo类型结果
     */
    @PostMapping("/mini-app/sales-leads/teachers")
    public QResult listTeachers(@RequestBody @Valid TeacherInfoQueryRequest request) {
        TeacherInfo t = new TeacherInfo();
        BeanUtils.copyProperties(request, t);
        return QResult.success(salesLeadsService.listTeachers(t, request.getPage(), request.getPageSize()));
    }
}